﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using octopus_project.screen;
using octopus_project.enumeration;
using octopus_project.scene.build;

namespace octopus_project.scene {
    class StatusBar_GameplayEntry : GameplayEntry {
        protected Vector2 position;
        protected Vector2 namePosition;
        protected Vector2 terrainPosition;
        protected Player ownerPlayer;
        SpriteFont playerNameFont, statsFont, statsBoldFont;
        private Build_Cursor buildcursor;


        public StatusBar_GameplayEntry (GameScreen gameScreen, Player ownerPlayer)
            : base(gameScreen) {
                this.ownerPlayer = ownerPlayer;
            playerNameFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/name");
            statsFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/stats");
            statsBoldFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/stats_bold");
        }

        public StatusBar_GameplayEntry(GameScreen gameScreen, Player ownerPlayer, Build_Cursor buildcursor)
            : base(gameScreen)
        {
            this.ownerPlayer = ownerPlayer;
            playerNameFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/name");
            statsFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/stats");
            statsBoldFont = ScreenManager.Game.Content.Load<SpriteFont>("fonts/stats_bold");
            this.buildcursor = buildcursor;
        }

        public override void Update () {
        }

        /// <summary>
        /// Description.
        /// </summary>
        public override void Draw () {
            switch(ownerPlayer.PlayerIndex) {
                case PlayerIndex.One:
                    position.X = 0;
                    position.Y = 0;
                    namePosition.X = position.X + 10;
                    namePosition.Y = position.Y + 10;
                    terrainPosition.X = namePosition.X;
                    terrainPosition.Y = namePosition.Y + 23;
                    
                    break;
                case PlayerIndex.Two:
                    position.X = Constant.WIDTH_RESOLUTION - SpriteExtensions.rectangleW;
                    position.Y = 0;
                    namePosition.X = position.X + 10;
                    namePosition.Y = position.Y + 10;
                    terrainPosition.X = namePosition.X;
                    terrainPosition.Y = namePosition.Y + 23;
                    break;
                case PlayerIndex.Three:
                    position.X = 0;
                    position.Y = Constant.HEIGTH_RESOLUTION - SpriteExtensions.rectangleH;
                    namePosition.X = position.X + 10;
                    namePosition.Y = position.Y + 10;
                    terrainPosition.X = namePosition.X;
                    terrainPosition.Y = namePosition.Y + 23;
                    break;
                case PlayerIndex.Four:
                    position.X = Constant.WIDTH_RESOLUTION - SpriteExtensions.rectangleW;
                    position.Y = Constant.HEIGTH_RESOLUTION - SpriteExtensions.rectangleH;
                    namePosition.X = position.X + 10;
                    namePosition.Y = position.Y + 10;
                    terrainPosition.X = namePosition.X;
                    terrainPosition.Y = namePosition.Y + 23;
                    break;
            }
            
            spriteBatch.Begin();
            spriteBatch.Draw(
                SpriteExtensions.SpriteImage,
                new Rectangle((int)position.X, (int)position.Y, SpriteExtensions.rectangleW, SpriteExtensions.rectangleH),
                Sprite.STATUS_BOX.GetSourceRectangle(ownerPlayer.Color),
                Color.White);
            spriteBatch.DrawString(playerNameFont, ownerPlayer.Name, namePosition, Color.Black);
            spriteBatch.DrawString(playerNameFont, ownerPlayer.Name, new Vector2(namePosition.X+1,namePosition.Y-1), Color.White);
            spriteBatch.DrawString(statsFont, "Conq: ", terrainPosition, Color.Black);
            spriteBatch.DrawString(statsBoldFont, ownerPlayer.Stats.TerrainConquered.ToString(), new Vector2(terrainPosition.X+43, terrainPosition.Y-1), Color.Black);
            if (buildcursor != null)
            {
                spriteBatch.DrawString(statsFont, "Next Tetrad: " + buildcursor.showNextTetrad(), new Vector2(terrainPosition.X - 1, terrainPosition.Y + 17), Color.Blue);
            }
            spriteBatch.End();
        }

    }
}
